package objects;
import java.awt.image.BufferedImage;


public class Concurrency extends Thread {
	int height = 0;
	int width = 0;
	static boolean f = true;
	MyShapeBuffers myShapes;
	BufferedImage img;
	Drawer drawer;
	
	private static boolean isRect;
	private static boolean isCircle;
	
	public Concurrency(BufferedImage img, BufferedImage output, boolean isC, boolean isR) {
		height = img.getHeight();
		width = img.getWidth();
		myShapes = new MyShapeBuffers();
		this.img = img;
		drawer = Drawer.getInstance();
		drawer.init(output);
		isRect = isR;
		isCircle = isC;
	}	
	
	public static boolean checkRect(){
		return isRect;
	}
	
	public static boolean checkCircle(){
		return isCircle;
	}
	
	public BufferedImage getImage(){
		return drawer.getImage();
	}
	
	public void run() {
		long t0, t1;

		t0 = System.currentTimeMillis();


		Finder f1 = new Finder(img,new Partition(width,height,1),myShapes, 1);
	
		Finder f2 = new Finder(img,new Partition(width,height,2),myShapes, 2);

		Finder f3 = new Finder(img,new Partition(width,height,3),myShapes, 3);

		Finder f4 = new Finder(img,new Partition(width,height,4),myShapes, 4);
		

		Checker c1 = new Checker(myShapes);
		
		Checker c2 = new Checker(myShapes);

		f1.start();
		f2.start();
		f3.start();
		f4.start();
		
		c1.start();
		c2.start();
		t1 = System.currentTimeMillis();
		
		while(f1.isAlive() || f2.isAlive() || f3.isAlive() || f4.isAlive()) {

		}
		f = false;

		while(c1.isAlive() || c2.isAlive()) {

		}
		System.out.println("Trwało to: " + (t1 - t0) + " ms.");	
	}
}

